<?php

class category {

    protected $db;
    protected $sql_query;
    protected $type;

    function  __construct($db) {
        $this->db = $db;
    }

    function setQuery($CategoryName){
        $this->sql_query = "SELECT * FROM category WHERE category_name='$CategoryName'";
    }

    function getHeader($path){

        $query = $this->db->query($this->sql_query);
        $header_str = '';
        while($row=$this->db->fetch($query)){
            $header_str .= '<h2 style="background: #FFF url('.$path.'images/category/'.$row['category_image'].') no-repeat; height: 30px; padding-left: 30px; font-size: 22px; color: #F79A09; ">'.$row['category_name'].'</h2>';
        }
        return $header_str;
    }

    function setComboQuery($SubCategoryID=null)
    {
        if($SubCategoryID==null){
            $this->sql_query = $this->db->query("SELECT category_id as CatID, category_name as CatName FROM category ORDER BY category_name");
        }else{
            $this->sql_query = $this->db->query("SELECT subcategory_id as CatID, subcategory_name as CatName FROM subcategory WHERE category_id='$SubCategoryID' ORDER BY subcategory_name");
        }
    }

    function getComboBox($Name, $SlectedID, $FirstRowStr=null, $Others=null)
    {
        $str_combo  = '';
        $str_combo   .= '<select name="'.$Name.'" '.$Others.'>';

        if($FirstRowStr!=null){
            $str_combo  .= '<option value="">'.$FirstRowStr.'</option>';
        }

        while($row = $this->db->fetch($this->sql_query)){
            if($row['CatID'] == $SlectedID){
                $str_combo  .= '<option value="'.$row["CatID"].'" selected="selected">'.$row['CatName'].'</option>';
            }else{
                $str_combo  .= '<option value="'.$row["CatID"].'">'.$row['CatName'].'</option>';
            }
        }

        $str_combo  .= '</select>';
        return $str_combo;
    }

}

?>
